package com.andnnl.reactor;

public class Server {
    Selector selector = new Selector();

    Dispatcher eventLooper = new Dispatcher(selector);

    Acceptor acceptor;

    Server(int port) {
        acceptor = new Acceptor(selector, port);
    }

    public void start() {
        eventLooper.registEventHandler(EventType.ACCEPT, new AcceptEventHandler(selector));
        eventLooper.registEventHandler(EventType.READ, new ReadEventHandler(selector));

        new Thread(acceptor, "Acceptor-" + acceptor.getPort()).start();

        eventLooper.handleEvents();

    }

    public void addTestSource(){
        for (int i = 0; i <10 ; i++) {
            acceptor.addNewConnection(new InputSource("test"+i,i));
        }
    }

}
